package com.pig4cloud.pig.village.family.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.village.api.dto.FamilySelect;
import com.pig4cloud.pig.village.api.dto.VillagerSelect;
import com.pig4cloud.pig.village.api.entity.Family;
import com.pig4cloud.pig.village.api.entity.Villager;
import com.pig4cloud.pig.village.family.mapper.FamilyMapper;
import com.pig4cloud.pig.village.family.service.IFamilyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author limbray.li
 * @date 2021/6/26
 */
@Service
@Slf4j
public class FamilyServiceImpl extends ServiceImpl<FamilyMapper, Family> implements IFamilyService {
	@Override
	public List<FamilySelect> listAllSelect() {
		List<Family> list = super.list();
		return convert(list);
	}

	private List<FamilySelect> convert(List<Family> list){
		List<FamilySelect> resultList = list.stream().map(e->{
			FamilySelect vo = new FamilySelect();
			vo.setId(e.getId());
			vo.setTeamId(e.getTeamId());
			vo.setName(e.getFamilyName());
			return vo;
		}).collect(Collectors.toList());
		return resultList;
	}

	@Override
	public List<FamilySelect> listByTeamIdSelect(Long teamId) {
		LambdaQueryWrapper<Family> query = Wrappers.lambdaQuery();
		query.eq(Family::getTeamId,teamId);
		List<Family> list = super.list(query);
		return convert(list);
	}
}
